To understand better how behaviors work and how you can create one, it's helpful to look at an example. The Configuration/Behaviors/Actions folder inside the Dreamweaver application folder is full of examples; however, many of these are likely to be too complex a starting point for all but the most advanced developers. The simplest action file to start with is Call JavaScript.htm (along with its counterpart, Call JavaScript.js, which contains all the JavaScript functions).
The following code also presents a relatively simple example. It checks the brand of the browser and goes to one page if the brand is Netscape, and another if the brand is Microsoft Internet Explorer. This code could easily be expanded to check for other brands—such as Opera and WebTV—and modified to perform other actions besides going to URLs.
<html><head><title>behavior "Check Browser Brand"</title><meta http-equiv="Content-Type" content="text/html"><script language="JavaScript"> // The function that will be inserted into the // HEAD of the user's document function checkBrowserBrand(netscapeURL,explorerURL) { if (navigator.appName == "Netscape") { if (netscapeURL) location.href = netscapeURL; }else if (navigator.appName == "Microsoft Internet Explorer") { if (explorerURL) location.href = explorerURL; } } //******************* API ********************** function canAcceptBehavior(){ return true; } // Return the name of the function to be inserted into // the HEAD of the user's document function behaviorFunction(){ return "checkBrowserBrand"; } // Create the function call that will be inserted // with the event handler function applyBehavior() { var nsURL = escape(document.theForm.nsURL.value); var ieURL = escape(document.theForm.ieURL.value); if (nsURL && ieURL) { return "checkBrowserBrand(\'" + nsURL + "\',\'" + ieURL + "\')"; }else{ return "Please enter URLs in both fields." } } // Extract the arguments from the function call // in the event handler and repopulate the // parameters form function inspectBehavior(fnCall){ var argArray = getTokens(fnCall, "()',"); var nsURL = unescape(argArray[1]); var ieURL = unescape(argArray[2]); document.theForm.nsURL.value = nsURL; document.theForm.ieURL.value = ieURL; } //***************** LOCAL FUNCTIONS ****************** // Put the cursor in the first text field // and select the contents, if any function initializeUI(){ document.theForm.nsURL.focus(); document.theForm.nsURL.select(); } // Let the user browse to the Navigator and // IE URLs function browseForURLs(whichButton){ var theURL = dreamweaver.browseForFileURL(); if (whichButton == "nsURL"){ document.theForm.nsURL.value = theURL; }else{ document.theForm.ieURL.value = theURL; } } //*************** END OF JAVASCRIPT ***************** </script></head><body><form method="post" action="" name="theForm"><table border="0" cellpadding="8"><tr><td nowrap="nowrap"> Go to this URL if the browser is Netscape Navigator:<br><input type="text" name="nsURL" size="50" value=""> <input type="button" name="nsBrowse" value="Browse..." onClick="browseForURLs('nsURL')"></td></tr><tr><td nowrap="nowrap"> Go to this URL is the browser is Microsoft Internet Explorer:<br><input type="text" name="ieURL" size="50" value=""> <input type="button" name="ieBrowse" value="Browse..." onClick="browseForURLs('ieURL')"></td></tr></table></form></body></html>